package com.java.merchant.controller;

import com.java.androidmarket.entity.Goods;
import com.java.androidmarket.entity.Result;

import com.java.androidmarket.utils.RedisUtils;
import com.java.merchant.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * description:
 * author:张腾
 * date:2021-07-23
 */

@RestController("merchant_goodsController")
@CrossOrigin
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private RedisUtils redisUtils;

    @PostMapping("addGoods")
    public Result addGoods(@RequestBody Goods goods){

        goodsService.insertGoods(goods);
        goodsService.deleteRedis();
        return Result.success(goods.getGoodsId());
    }

    @PostMapping("update")
    public Result updateGoods(@RequestBody Goods goods){

        goodsService.updateGoods(goods);
        goodsService.deleteRedis();
        return Result.success();
    }

    @PostMapping("del")
    public Result deleteGoods(@RequestBody Goods goods){

        goodsService.deleteGoods(goods.getGoodsId());
        goodsService.deleteRedis();
        return Result.success();
    }

    @GetMapping("test")
    public Result test(String text){
        return Result.success(text);
    }
}
